package com.matt.repository.impl;

import com.matt.foundation.vo.CountRecordstVo;
import com.matt.repository.CountRecordRepository;
import com.matt.repository.base.BaseNativeSqlRepository;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CountRecordRepositoryImpl extends BaseNativeSqlRepository implements CountRecordRepository {

	@Override
	public List<CountRecordstVo> countRecord(String childId) {
		String findSql = "";
		findSql += "SELECT a.countDrug,b.countDefecation,c.countHospital,d.countDiet,e.countHandover,f.countReport from ";
		findSql += String.format( " (SELECT COUNT(id) AS countDrug FROM `tb_record_drug_delivery` WHERE childId = '%s') a, ",childId); 
		findSql += String.format( " (SELECT COUNT(id) AS countDefecation FROM `tb_record_defecation` WHERE childId = '%s') b," ,childId);
		findSql += String.format( " (SELECT COUNT(id) AS countDiet FROM `tb_record_diet` WHERE recordType = 0 AND childId = '%s') d," ,childId);
		findSql += String.format( " (SELECT COUNT(id) AS countHandover FROM `tb_record_handover` WHERE childId = '%s') e," ,childId);
		findSql += String.format( " (SELECT COUNT(id) AS countReport FROM `tb_record_diet` WHERE recordType = 1 AND childId = '%s') f," ,childId);
		findSql += String.format( " (SELECT COUNT(id) AS countHospital FROM `tb_record_hospital` WHERE childId = '%s') c",childId);
        List<CountRecordstVo> list = sqlObjectList(findSql,CountRecordstVo.class);
		return list;
	}



    
}
